﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Budget
{
    abstract class Undo
    {
        protected DataGridView m_dgv;

        public Undo(ref DataGridView i_dgv)
        {
            m_dgv = i_dgv;
        }
        
        public abstract void Activate();
    }

    class UndoEdit : Undo
    {
        MyDataGridCell m_cell;
        public UndoEdit(ref DataGridView i_dgv,MyDataGridCell i_cell) : base(ref i_dgv)
        {
            m_cell = i_cell;
        }
        public override void Activate()
        {
            m_dgv.Rows[m_cell.RowNumber].Cells[m_cell.ColumnNumber].Value = m_cell.Value;
        }
    }

    class UndoRowDelete : Undo
    {
        DataRow m_row;
        DataTable m_dataTable;
        int m_index;

        public UndoRowDelete(DataTable i_dataTable,DataGridView i_dataGridView,DataRow i_row) : base(ref i_dataGridView)
        {
            m_dataTable = i_dataTable;
            m_row = i_dataTable.NewRow();
            m_row.ItemArray = i_row.ItemArray.Clone() as object[];
            m_index = i_dataGridView.CurrentCell.RowIndex;
        }

        public override void Activate()
        {
            m_dataTable.Rows.InsertAt(m_row,m_index); 
        }
    }
}
